package com.arrays;

public class SquaresofaSortedArray0124_977 {
    public int[] sortedSquares(int[] nums) {
        int left=0,right=nums.length-1;
        int n = nums.length -1;
        int[] res = new int[nums.length];
        while (left<=right){
            int l = nums[left] * nums[left];
            int r = nums[right] * nums[right];
            if(l > r) {
                res[n] = l;
                left++;
            } else {
                res[n] = r;
                right--;
            }
            n--;
        }
        return res;
    }
}
